package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.basebean.ListPageBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.google.gson.JsonObject;
import com.lzm.ydpt.entity.UserOrderBean;
import com.lzm.ydpt.module.order.fragment.UserOrderListFragment;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.UserOrderListContract;
import com.lzm.ydpt.mvp.modelimpl.UserOrderListModelImpl;

/**
 * 类名称：UserOrderListPresenterImpl
 * 类描述：代理实现
 */
public class UserOrderListPresenterImpl extends BasePresenter implements UserOrderListContract.Presenter {

    private UserOrderListContract.View mView;
    private UserOrderListContract.Model mModel;

    public UserOrderListPresenterImpl(UserOrderListFragment context) {
        super(context.getActivity());
        this.mView = context;
        this.mModel = new UserOrderListModelImpl();
    }

    @Override
    public void onUserOrderList(FormBodys formBodys) {
        mManager.http(mModel.onUserOrderList(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<ListPageBean<UserOrderBean>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<ListPageBean<UserOrderBean>> entity) {
                mView.onUserOrderList(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showErrorView(e.getDisplayMessage());
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showErrorView(entity.getMessage());
            }
        }, "onUserOrderList"));
    }
}